package com.fractalist.base.core;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 
 * 加载资源文件的类
 *
 */
public class ConfigurableContants {

	private static final Logger logger = Logger
			.getLogger(ConfigurableContants.class);

	protected static Properties props = new Properties();

	/**
	 * 初始化加载资源文件
	 * 
	 * @param propertyFileName	资源文件名称
	 */
	protected static void init(String propertyFileName) {
		InputStream in = null;
		try {
			in = ConfigurableContants.class
					.getResourceAsStream(propertyFileName);
			if (in != null)
				props.load(in);
		} catch (IOException e) {
			logger.error("load " + propertyFileName + " into Contants error");
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
				}
			}
		}
	}

	protected static String getProperty(String key, String defaultValue) {
		return props.getProperty(key, defaultValue);
	}
}
